<?php

namespace app\home\model;
use think\Model;
use think\Db;

class ProductModel extends Model
{

    protected $name = 'product';

    /**
     * getOneIsTuiEQThree [ 取出重点推荐（id_tui = 3） ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getOneIsTuiEQThree()
    {
        return Db::name('product')
                ->field('think_product.*,name')
                ->join('think_product_cate', 'think_product.cate_id = think_product_cate.id')
                ->where(array('think_product.is_tui' => 3))
                ->order('id desc')
                ->find();
    }


    /**
     * getNewProductFour [ 取出四条最新的产品需求 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getNewProductFour()
    {
        return Db::name('product')
            ->field('think_product.*,name')
            ->join('think_product_cate', 'think_product.cate_id = think_product_cate.id')
            ->order('id desc')
            ->select();

    }


    /**
     * getSuccessSixProduct [ 取出6成功的产品需求 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getSuccessSixProduct()
    {
        return Db::name('product')
            ->field('think_product.*,name')
            ->join('think_product_cate', 'think_product.cate_id = think_product_cate.id')
            ->order('id desc')
            ->limit(6)
//            ->where()
            ->select();

    }

    /**
     * getSuccessSixProduct [ 取出15条最新的产品需求 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getTenFiveProduct()
    {
        return Db::name('product')
            ->field('think_product.*,name')
            ->join('think_product_cate', 'think_product.cate_id = think_product_cate.id')
            ->order('id desc')
            ->limit(15)
            ->select();

    }




    /**
     * fetchOneProduct [ 根据传值Id 查询当前产品 详情页 ]
     * @author [Boot.Z] [852952656@qq.com]
     * @param $id
     */
    public function fetchOneProduct($id)
    {
        return Db::name('product')
                ->where('id',$id)
                ->field('think_product.*')
                ->find();
    }

    /**
     * getAllProductCate [ 取出所有的产品分类 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getAllProductCate()
    {
        return Db::name('product_cate')
            ->field('think_product_cate.*')
            ->select();
    }

    /**
     * getAllproduct [ 取出全部的分类 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getAllproduct()
    {
        return Db::name('product')
            ->field('think_product.*')
            ->select();
    }


    /**
     * getHomeview [ 取出前端显示4条全部信息 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getHomeviewAll ()
    {
        return Db::name('product')
            ->field('think_product.*,name')
            ->join('think_product_cate', 'think_product.cate_id = think_product_cate.id')
            ->order('id asc')
            ->limit(4)
            ->select();
    }

    /**
     * getHomeViewhot [ 取出四条热需求 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getHomeViewhot()
    {
        return Db::name('product')
            ->field('think_product.*,name')
            ->join('think_product_cate', 'think_product.cate_id = think_product_cate.id')
            ->order('views desc')
            ->limit(4)
            ->select();
    }

    /**
     * getHomeViewNew [ 取出最新四条加盟商 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getHomeViewNew()
    {
        return Db::name('product')
            ->field('think_product.*,name')
            ->join('think_product_cate', 'think_product.cate_id = think_product_cate.id')
            ->order('id desc')
            ->limit(4)
            ->select();
    }
    
    
    
    
    
    
    //---------------------------------------------------
    //  暂定，待用
    //---------------------------------------------------

    /**
     * [getAllCate 获取产品分类]
     * @author [张家恒] [852952656@qq.com]
     */
    public function getOneNews($id)
    {
        return Db::name('product')
                ->field('id,title,content,create_time,update_time,writer,remark')
                ->where(array('id' => $id))
                ->find();


    }

    /**
     * fetchSuiJiNews [ 随机取出10条新闻 ]
     * @author [Boot.Z] [852952656@qq.com]
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function fetchSuiJiNews()
    {
        return  Db::name('article')
                ->order("rand()")
                ->field('id,title')
                ->limit(10)
                ->select();

    }

    /**
     * NextArticle [ 下一条新闻 ]
     * @author [Boot.Z] [852952656@qq.com]
     * @return array|false|\PDOStatement|string|Model
     * @param $id
     */
    public function NextArticle($id)
    {
        return  Db::name('product')
            ->where("id",'>',$id)
            ->field('id,title,remark ')
            ->order('id asc')
            ->limit('1')
            ->find();
    }

    /**
     * getIdWherePilise [ 取出当前id为政策法规的全部新闻 ]
     * @author [Boot.Z] [852952656@qq.com]
     * @return array|false|\PDOStatement|string|Model
     * @param $id
     */
    public function getIdWherePilise($id,$p_id)
    {
        return  Db::name('product')
            ->where(array('cate_id' => $p_id,'id' => $id))
            ->field('id,title,remark,content,update_time,writer')
            ->order('id desc')
            ->find();

    }


    /**
     * getAllPoliseTitleAndId [取出政策法规所有的标题跟ID  ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getAllPoliseTitleAndId($pid)
    {
        return  Db::name('product')
                ->where(array('cate_id' => $pid))
                ->field('id,title')
                ->order('id desc')
                ->select();
    }


    /**
     * getPoliseNewOne [ 取出最新的一个政策法规 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getPoliseNewOne($p_id)
    {
        return  Db::name('product')
                ->where(array('cate_id' => $p_id))
                ->where('id','<','100000')
                ->field('id')
                ->order('id desc')
                ->limit('1')
                ->find();
    }

    /**
     * fetchCateIDNewsAll [ 根据ID查询当前在ID内的所有新闻 ]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function fetchCateIDNewsAll($id)
    {
        return Db::name('product')
                ->where('cate_id','in',$id)
                ->order('id desc')
                ->paginate(4);
    }





}